
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region GRNDetailDAL
	public class GRNDetailDAL : DBContext
	{
		public List<GRNDetail> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNDetailsSelectAll");
            return GetEntityList<GRNDetail>(cmd);
        }

        public List<GRNDetail> GetByMasterId(Guid grnMasterId)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNDetailsSelectByMasterId");
            cmd.AddParameter("@GRNMasterId", grnMasterId);
            return GetEntityList<GRNDetail>(cmd);
        }

        public GRNDetail Add(Guid paramGRNMasterId, Guid paramProductId, Guid paramUnitId, decimal paramQuantity,
                                    decimal paramUnitCost, decimal paramTotal, decimal paramSoldQty, bool paramIsConsignment,
                                    decimal paramConsignmentCommission, string paramRemark, string paramCreatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNDetailInsert");
            cmd.AddParameter("@GRNMasterId", paramGRNMasterId);
            cmd.AddParameter("@ProductId", paramProductId);
            cmd.AddParameter("@UnitId", paramUnitId);
            cmd.AddParameter("@Quantity", paramQuantity);
            cmd.AddParameter("@UnitCost", paramUnitCost);
            cmd.AddParameter("@Total", paramTotal);
            cmd.AddParameter("@SoldQty", paramSoldQty);
            cmd.AddParameter("@IsConsignment", paramIsConsignment);
            cmd.AddParameter("@ConsignmentCommission", paramConsignmentCommission);
            cmd.AddParameter("@Remark", paramRemark);
            cmd.AddParameter("@CreatedBy", paramCreatedBy);
            return GetSingleEntity<GRNDetail>(cmd);
        }

		public List<GRNDetail> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNDetailSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<GRNDetail>(cmd);
        } 
		

        public GRNDetail UpdateById(Guid paramGRNMasterId, Guid paramProductId, Guid paramUnitId, decimal paramQuantity,
                                    decimal paramUnitCost, decimal paramTotal, decimal paramSoldQty, bool paramIsConsignment,
                                    decimal paramConsignmentCommission, string paramRemark, string paramUpdatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNDetailUpdate");
			cmd.AddParameter("@GRNMasterId", paramGRNMasterId);
			cmd.AddParameter("@ProductId", paramProductId);
			cmd.AddParameter("@UnitId", paramUnitId);
			cmd.AddParameter("@Quantity", paramQuantity);
			cmd.AddParameter("@UnitCost", paramUnitCost);
			cmd.AddParameter("@Total", paramTotal);
			cmd.AddParameter("@SoldQty", paramSoldQty);
			cmd.AddParameter("@IsConsignment", paramIsConsignment);
			cmd.AddParameter("@ConsignmentCommission", paramConsignmentCommission);
			cmd.AddParameter("@Remark", paramRemark);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            return GetSingleEntity<GRNDetail>(cmd);
        }

        public bool PhysicalDeleteById(Guid masterId, Guid productId)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNDetailPhysicalDelete");
            cmd.AddParameter("@GRNMasterId", masterId);
            cmd.AddParameter("@ProductId", productId);
            return ExecuteCommand(cmd);
        }
		
	}
	#endregion
}
